//
//  PaymentTypeViewController.m
//  WorkManager
//
//  Created by iD Student on 7/18/12.
//  Copyright (c) 2012 iD Student. All rights reserved.
//

#import "PaymentTypeViewController.h"

@implementation PaymentTypeViewController

@synthesize appointmentReport;
@synthesize cashCell;
@synthesize checkCell;
@synthesize creditCell;
@synthesize paypalCell;
@synthesize otherCell;

- (void)uncheckCellAtIndex:(int)oldIndex andCheckCellAtIndex:(int)newIndex
{
    [[cells objectAtIndex:(oldIndex-1)] setAccessoryType:UITableViewCellAccessoryNone];
    [[cells objectAtIndex:newIndex] setAccessoryType:UITableViewCellAccessoryCheckmark];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    currentCheckedRow = [appointmentReport paymentType];
    [[cells objectAtIndex:(currentCheckedRow-1)] setAccessoryType:UITableViewCellAccessoryCheckmark];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [appointmentReport setPaymentType:currentCheckedRow];
    [appointmentReport release];
    appointmentReport = nil;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    cells = [[NSArray alloc] initWithObjects:cashCell, checkCell, creditCell, paypalCell, otherCell, nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self uncheckCellAtIndex:currentCheckedRow andCheckCellAtIndex:[indexPath row]];
    currentCheckedRow = [indexPath row]+1;
    [[cells objectAtIndex:[indexPath row]] setSelected:NO];
}

- (void)dealloc {
    [cashCell release];
    [checkCell release];
    [creditCell release];
    [paypalCell release];
    [otherCell release];
    [super dealloc];
}
@end
